import com.Lyy.Mapper.StudentMapper;
import com.Lyy.cla.MBStudent;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import com.Lyy.uity.MBgetSession;

import java.io.IOException;
import java.util.List;

public class student {
    @Test
    public void select() throws IOException {
        SqlSession sqlSession = MBgetSession.getsqlSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        List<MBStudent> mbStudents = mapper.MBSelectStudentAll();
        System.out.println(mbStudents);

    }

    @Test
    public void update() throws IOException {
        SqlSession sqlSession = MBgetSession.getsqlSession();
        MBStudent MBStudentUpd = new MBStudent(6, "test7");
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        int num = mapper.MBUpdStudent(MBStudentUpd);
        sqlSession.commit();
        if (num > 0) {
            System.out.println("成功修改" + num + "条信息");
        }else{
            System.out.println("未作更改");
        }
    }

    @Test
    public void dele() throws IOException {
        SqlSession sqlSession = MBgetSession.getsqlSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        int num = mapper.MBDelStudent(6);
        sqlSession.commit();
        if (num > 0) {
            System.out.println("成功删除" + num + "条信息");
        }else{
            System.out.println("未作更改");
        }

    }

    @Test
    public void add() throws IOException {
        SqlSession sqlSession = MBgetSession.getsqlSession();
        MBStudent MBStudentAdd = new MBStudent(6, "test6");
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        int num = mapper.MBAddStudent(MBStudentAdd);
        sqlSession.commit();
        if (num > 0) {
            System.out.println("成功添加" + num + "条信息");
        }else{
            System.out.println("未作更改");
        }
    }

}
